#!/bin/bash

### BEGIN INIT INFO
# Provides:          setup-board
# Required-Start:    $portmap
# Required-Stop:
# Should-Start:
# Should-Stop:
# Default-Start:     S
# Default-Stop:      0 6
# Short-Description: Setup 200i board.
### END INIT INFO

case "$1" in
start)
        echo -n "Setting up board... "

        # Attach TLV 0x56 eeprom
        echo 24lc64t 0x56 > /sys/bus/i2c/devices/i2c-0/new_device
        sleep 2

        modprobe 200i-cpld
        sleep 2

        # Turn off/down lpmod by defult (0 - Normal, 1 - Low Pow)
        echo 0x00 > /sys/devices/platform/ms200i_cpld/qsfp_lpmode

        # Attach 64 instances of EEPROM driver QSFP ports
        for ((n=1;n<=66;n++));
        do
                echo sff8436 0x50 > /sys/bus/i2c/devices/i2c-$n/new_device
        sleep 0.1
        done

        echo "done."
        ;;

stop)
        echo "done."
        ;;

force-reload|restart)
        echo "Not supported"
        ;;

*)
        echo "Usage: /etc/init.d/platform-modules-200i.init {start|stop}"
        exit 1
        ;;
esac

exit 0
